﻿@using TamoCRM.Core
@using TamoCRM.Domain.Groups
@using TamoCRM.Domain.Majors
@using TamoCRM.Domain.Schools
@using TamoCRM.Domain.UserRole
@using TamoCRM.Web.Framework.Users
@{
    ViewBag.Title = "Báo cáo khối lượng công việc TVTS";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";

    // Group
    var groups = ViewBag.Groups;
    var user = UserContext.GetCurrentUser();
    if (user.GroupType != (int)GroupType.ManagerTVTS)
    {
        groups = ((List<GroupInfo>)groups).Where(c => c.LeaderId == user.UserID || c.GroupId == (int)ViewBag.GroupId).ToList();
    }

    ((List<GroupInfo>)groups).RemoveAll(c => c.GroupId == 0);
    if (((List<GroupInfo>)groups).Count > 1)
    {
        ((List<GroupInfo>)groups).Insert(0, new GroupInfo { GroupId = 0, Name = "Tất cả" });
    }
    var branchId = UserContext.GetDefaultBranch();
    var lstGroups = new SelectList(((List<GroupInfo>)groups).Where(c => c.BranchId == branchId), "GroupId", "Name");

    // User
    var users = ViewBag.Users;
    ((List<UserInfo>)users).RemoveAll(c => c.GroupId == 0);
    ((List<UserInfo>)users).Insert(0, new UserInfo { UserID = 0, FullName = "Tất cả" });
    var lstUsers = new SelectList(users, "UserID", "FullName");

    // School
    var schools = ViewBag.Schools;
    ((List<SchoolInfo>)schools).RemoveAll(c => c.SchoolId == 0);
    ((List<SchoolInfo>)schools).Insert(0, new SchoolInfo { SchoolId = 0, Name = "Tất cả" });
    var lstSchools = new SelectList(schools, "SchoolId", "Name");

    // Major
    var majors = ViewBag.Majors;
    ((List<MajorInfo>)majors).RemoveAll(c => c.MajorId == 0);
    ((List<MajorInfo>)majors).Insert(0, new MajorInfo { MajorId = 0, Name = "Tất cả" });
    var lstMajors = new SelectList(majors, "MajorId", "Name");
}
<div class="breadcrumbs" id="breadcrumbs">
    <script type="text/javascript">
        try {
            ace.settings.check('breadcrumbs', 'fixed');
        } catch (e) { }
    </script>

    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            <a href="/Home">Trang chủ</a>
        </li>

        <li>
            <a href="javascript:void(0);">Danh mục</a>
        </li>
        <li class="active">Báo cáo khối lượng công việc TVTS</li>
    </ul>
</div>

<div class="page-content">
    <div class="page-header">
        <h1>Báo cáo khối lượng công việc TVTS
        </h1>
    </div>
    <div class="row">
        <div class="form-group">
            <div class="col-sm-12" id="alert">
            </div>
        </div>
        <div class="col-xs-12">
            @using (Ajax.BeginForm("BC04", "Report", new AjaxOptions { HttpMethod = "POST" }, new { enctype = "multipart/form-data", @class = "form-horizontal", role = "form", id = "uploadexcelform" }))
            {
                @Html.AntiForgeryToken()
                <div class="row">
                    <label class="col-sm-1 control-label no-padding-right" style="text-align: left !important;" for="form-field-2">Nhóm </label>
                    <div class="col-sm-2">
                        @Html.DropDownList("GroupId", lstGroups, new { @class = "form-control" })
                    </div>
                    <label class="col-sm-1 control-label no-padding-right" style="text-align: left !important;" for="form-field-2">TVTS</label>
                    <div class="col-sm-2">
                        @Html.DropDownList("UserId", lstUsers, new { @class = "form-control" })
                    </div>
                </div>
                <div class="space-6"></div>
                <div class="row">
                    <label class="col-sm-1 control-label no-padding-right" style="text-align: left !important;" for="form-field-2">Trường </label>
                    <div class="col-sm-2">
                        @Html.DropDownList("SchoolId", lstSchools, new { @class = "form-control" })
                    </div>
                    <label class="col-sm-1 control-label no-padding-right" style="text-align: left !important;" for="form-field-2">Nghành </label>
                    <div class="col-sm-2">
                        @Html.DropDownList("MajorId", lstMajors, new { @class = "form-control" })
                    </div>
                    <label class="col-sm-1 control-label no-padding-right" style="text-align: left !important;" for="form-field-2">Từ ngày </label>
                    <div class="col-sm-2">
                        @Html.TextBox("FromDate", DateTime.Now.ToString("dd/MM/yyyy"), new { @class = "form-control" })
                    </div>
                    <label class="col-sm-1 control-label no-padding-right" style="text-align: left !important;" for="form-field-3">Đến ngày </label>
                    <div class="col-sm-2">
                        @Html.TextBox("ToDate", DateTime.Now.ToString("dd/MM/yyyy"), new { @class = "form-control" })
                    </div>
                </div>
                <div class="space-6"></div>
                <div class="row">
                    <div class="col-sm-5">
                        <button type="button" class="btn-import btn-primary" id="btnReport">Xuất báo cáo</button>
                    </div>
                    <div class="col-sm-7">
                    </div>
                </div>
            }

            <div class="space-6"></div>
            <div id="mydiv">
                <iframe id="frame" style="width: 100%; height: 400px; border: none;"></iframe>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        initPage();

        $("#btnReport").click(function (e) {
            e.preventDefault();
            if ($("#FromDate").val() == '' || $("#ToDate").val() == '') {
                alertError("Bạn chưa chọn khoảng thời gian tìm kiếm");
                return;
            }

            var toDate = $("#ToDate").val();
            var userId = $("#UserId").val();
            var groupId = $("#GroupId").val();
            var majorId = $("#MajorId").val();
            var branchId = '@ViewBag.BranchId';
            var schoolId = $("#SchoolId").val();
            var fromDate = $("#FromDate").val();

            var url = '/admin/report/showbc04?groupId={0}&userId={1}&schoolId={2}&majorId={3}&branchId={4}&from={5}&to={6}';
            var url = url.format(groupId, userId, schoolId, majorId, branchId, fromDate, toDate);
            $("#frame").attr("src", url);
        });
    });

    function initPage() {
        $("#FromDate").datepicker({ format: 'dd/mm/yyyy', autoclose: true });
        $("#ToDate").datepicker({ format: 'dd/mm/yyyy', autoclose: true });
        
        // Group
        $("#GroupId").change(function () {
            loadUserByGroupId();
        });

        loadUserByGroupId();
    }
</script>
